 
import { ABaseDecision } from "GameLoop/DecisionMaking/BaseDecision";
 
import { MineEntity } from "GameLoop/WorldState/EntityManager/Entitys/room/mine/MineEntity";
import { priority } from "utils/constants/definetypes";
 

/**
 * 检测发布修ram的任务
 */
export class TowerRepairRampasrtDecision< T extends "tower"="tower"> extends ABaseDecision<T>
{
    public isExpired(event: NormalEvent, region: string): boolean 
    {
        return true;
    }
    public makeTask(event: NormalEvent, region: string): IDecisionCode<T>|false
    {
        const room = Game.rooms[event.region] as Required<Room>;
        const structurecache = room.getWorld().PollStructure(room.name);
        if(structurecache)
        {
            const rams = structurecache.getStructure(STRUCTURE_RAMPART,e=>e.hits<5000);
            if(rams && rams?.length>0)
            {
                if(room.towers().length>0)
                {
                    const goal:Record<string,number>={};
                    rams.forEach(e=> goal[e.id]=6000)
                    const task = room.getTaskById<ITaskDeclare["tower"]>(`${event.room}_tower_repair_ram`,["tower"]);
                    if(task)
                    {
                        task.data.arg={
                            room: room.name,
                            targets: goal
                        }
                        return false;
                    }

                    const repairTask:IRoomTaskData<"towerRepair"> = 
                    {
                        type: "towerRepair",
                        arg: {
                            room: room.name,
                            targets: goal
                        }
                    }
                    const code:IDecisionCode<T>={
                        region:event.region,
                        isunique:false,
                        task:[{
                            id:`${event.room}_tower_repair_ram`,
                            ttl:5000,
                            priority:priority.C,
                            type:"tower",
                            data:repairTask,
                            shard:0,
                        } as any],
                    }
                    return code
                }
            }
        }
        return false;
        // return code
    }
     
}